package com.maoge.main;

import com.maoge.annotation.Maoge;
import com.maoge.controller.TestController;
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner;
import io.github.lukehutch.fastclasspathscanner.scanner.ClassInfo;
import io.github.lukehutch.fastclasspathscanner.scanner.MethodInfo;
import io.github.lukehutch.fastclasspathscanner.scanner.ScanResult;
import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by bjmaozhengwei on 2018/7/4.
 */
public class Main {


    public static void main(String[] args) {
        FastClasspathScanner fastClasspathScanner = new FastClasspathScanner("com.maoge");
        ScanResult scan = fastClasspathScanner.enableMethodInfo().scan();
        Map<String, ClassInfo> classNameToClassInfo = scan.getClassNameToClassInfo();

        for (String str :classNameToClassInfo.keySet()) {
            ClassInfo classInfo = classNameToClassInfo.get(str);
            List<MethodInfo> methodInfos = classInfo.getMethodAndConstructorInfo();
            for (MethodInfo methodInfo:methodInfos) {
                System.out.println("Main.getAnnotations " + methodInfo.getClassName());
                System.out.println("Main.getAnnotations " + methodInfo.getMethodName());
                System.out.println("Main.getAnnotations " + methodInfo.getModifiersStr());
                System.out.println("Main.getAnnotations " + methodInfo.getTypeDescriptorStr());
                System.out.println("Main.getAnnotations " + methodInfo.getTypeDescriptor());
                System.out.println("Main.getAnnotations " + methodInfo.getTypeSignatureStr());
                System.out.println("Main.getAnnotations " + methodInfo.getAnnotationInfo());
                System.out.println("Main.getAnnotations " + methodInfo.getParameterNames());
                System.out.println("Main.getAnnotations " + methodInfo.toString());
            }
        }


    }


    public static void test(){
        Reflections reflections = new Reflections(new MethodAnnotationsScanner());

        Set<Method> fieldsAnnotatedWith = reflections.getMethodsAnnotatedWith(Maoge.class);

        for (Method method : fieldsAnnotatedWith) {
            Annotation[] annotations = method.getAnnotations();
            for (Annotation annotation : annotations) {
                Class<? extends Annotation>  aClass = annotation.annotationType();
                Class<? extends Annotation> aClass2 = annotation.getClass();
                aClass2.getCanonicalName();
                Class<? extends Class> aClass1 = aClass.getClass();
                Class<?> componentType = aClass.getComponentType();
                String name = aClass.getName();
                Annotation[] annotations1 = aClass.getAnnotations();
                System.out.println("Main.getAnnotations " + annotation.toString());
            }
            System.out.println("Main.getAnnotations " + method.getAnnotations());
            System.out.println("Main.getAnnotations " + method.getName());
            System.out.println("Main.getAnnotations " + method.getAnnotatedReturnType());
        }
    }
}
